﻿//模板
var menuTemplate = "<ul>" +
                                "{for p in Rows}" +
                                    "{if p.Menu_Leaf=='0'}" +
                                     "<li class=\"floatleft ${p.CustomMenuCss}\"><span onclick=\"loadCustomMenu('${p.User_Code}','${p.Menu_ID}',1,'${p.Menu_Level}');\">" +
                                        "<div class=\"menutop\">" +
                                        "</div>" +
                                        "<div class=\"menubottom\">" +
                                        "${p.Menu_Title}</div>" +
                                      "</span></li>" +
                                    "{else}" +
                                    "<li class=\"floatleft ${p.CustomMenuCss}\"><span onclick=\"openPanelWithMenu('${p.Menu_ID}');\">" +
                                        "<div class=\"menutop\">" +
                                        "</div>" +
                                        "<div class=\"menubottom\">" +
                                        "${p.Menu_Title}</div>" +
                                      "</span></li>" +
                                    "{/if}" +
                               "{/for}" +
                            "</ul>";

var menuTemplateno = "<ul>" +
                                "{for p in Rows}" +
                                    "{if p.Menu_Leaf=='0'}" +
                                     "<li class=\"floatleft ${p.CustomMenuCss}\"><span onclick=\"openGroupMenu('${p.Menu_ID}','${p.Menu_Title}','GroupMenu.aspx?parentMenuId='+'${p.Menu_ID}'+'&type=1&group='+'${p.Menu_Level}');\">" +
                                        "<div class=\"menutop\">" +
                                        "</div>" +
                                        "<div class=\"menubottom\">" +
                                        "${p.Menu_Title}</div>" +
                                      "</span></li>" +
                                    "{else}" +
                                    "<li class=\"floatleft ${p.CustomMenuCss}\"><span onclick=\"openPanelWithMenu('${p.Menu_ID}');\">" +
                                        "<div class=\"menutop\">" +
                                        "</div>" +
                                        "<div class=\"menubottom\">" +
                                        "${p.Menu_Title}</div>" +
                                      "</span></li>" +
                                    "{/if}" +
                               "{/for}" +
                            "</ul>";

var menuTemplateGroup = "{for p in Rows}" +
                        "<div class=\"flbt\">" +
                            "<div class=\"flbt01l\">" +
                            "</div>" +
                            "<div class=\"flbt02\">" +
                                "${p.Menu_Title}</div>" +
                            "<div class=\"flbt02r\">" +
                            "</div>" +
                            "<div class=\"flbt01r\">" +
                            "</div>" +
                            "<div class=\"flbt03r\">" +
                            "</div>" +
                        "</div>" +
                        "<div id=\"${p.Menu_ID}\" class=\"groupmenu\">" +
                            "<img alt=\"加载中...\" title=\"加载中...\" src=\"res/images/framework/loading.gif\" class=\"loadimg\" />" +
                        "</div>" +
                        "{/for}";


var hashTableByMenu = new HashTable();
//地区html代码生成
function loadCustomMenu(userCode, menuParentId, type, menuGroup) {
    if (!hashTableByMenu.ContainsKey(menuParentId)) {
        function OnSuccess(result) {
            if (result.Rows != null) {
                $("#customMenu").html('<img src="res/images/framework/loading.gif" />');
                if (type == 0) {
                    html = TrimPath.parseTemplate(menuTemplateno).process(result);
                    $("#goTopBtn").css('display', 'none');
                }
                else {
                    html = TrimPath.parseTemplate(menuGroup == '0' ? menuTemplate : menuTemplateGroup).process(result);
                    $("#goTopBtn").css('display', '');
                }
                $("#customMenu").html(html);
                hashTableByMenu.Add(menuParentId, html);
                $("#customMenu").css('display', 'none');
                if (type == 0) {
                    $("#customMenu").fadeIn("fast");
                }
                else {
                    $("#customMenu").fadeIn("slow");
                }
                if (menuGroup == '1') {
                    loadGroupMenu(userCode, 0);
                }
            }
        }
        $.ajax({ type: "POST", url: "Data/MainPageCustom.ashx", data: "m=GetCustomMenu&usercode=" + userCode + "&menuparentid=" + menuParentId, dataType: "json", success: OnSuccess });
    }
    else {
        var result = hashTableByMenu.GetValue(menuParentId);

        $("#customMenu").html(result);
        $("#customMenu").css('display', 'none');
        if (type == 0) {
            $("#goTopBtn").css('display', 'none');
            $("#customMenu").fadeIn("fast");
        }
        else {
            $("#goTopBtn").css('display', '');
            $("#customMenu").fadeIn("slow");
        }
        if (menuGroup == '1') {
            loadGroupMenu(userCode, 0);
        }
    }
}

function loadGroupMenu(userCode, i) {
    var objGroupMenu = $(".groupmenu");
    if (objGroupMenu != null && objGroupMenu.length > 0) {
        if (i < objGroupMenu.length) {
            menuParentId = objGroupMenu[i].id;
            if (!hashTableByMenu.ContainsKey(menuParentId)) {
                function OnSuccess(result) {
                    if (result.Rows != null) {

                        html = TrimPath.parseTemplate(menuTemplate).process(result);

                        $("#" + menuParentId).html(html);
                        hashTableByMenu.Add(menuParentId, html);
                        i = i + 1;
                        loadGroupMenu(userCode, i);
                    }
                }
                function OnError(XMLHttpRequest, textStatus, errorThrown) {
                    //alert(errorThrown);
                    $("#" + menuParentId).html("");
                    i = i + 1;
                    loadGroupMenu(userCode, i);
                }
                $.ajax({ type: "POST", url: "Data/MainPageCustom.ashx", data: "m=GetCustomMenu&usercode=" + userCode + "&menuparentid=" + menuParentId,
                    dataType: "json", success: OnSuccess, error: OnError
                });
            }
            else {
                var result = hashTableByMenu.GetValue(menuParentId);

                $("#" + menuParentId).html(result);
                i = i + 1;
                loadGroupMenu(userCode, i);
            }
        }
    }
}

// 待办事宜 模板
var rightTemplateByZjzx = "<ul>" +
                            "{if Rows[0].MarketCollectCount!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithMenu('001003001');\">${Rows[0].MarketCollectCount}</a></span> 个尚未划入的市场货款信息</li>" +
                             "{/if}" +
                             "{if Rows[0].Pay_Count!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithMenu('001003002');\">${Rows[0].Pay_Count}</a></span>条尚未处理的货款申请</li>" +
                             "{/if}" +
                             "{if Rows[0].Collect_Count!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxCollect','未划入的划转明细','Remind/PadBilling.aspx');\">${Rows[0].Collect_Count} </a></span>条尚未划入的划转明细</li>" +
                             "{/if}" +
                             "{if Rows[0].BadContract_Count!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxBadContract','未处理的合同终止列表','Remind/BadContracting.aspx');\">${Rows[0].BadContract_Count} </a></span>条尚未处理的终止信息</li>" +
                             "{/if}" +
                           "</ul>";

//待办事宜 模板
var rightTemplateByFgs = "<ul>" +
                            "{if Rows[0].Pay_Count!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithMenu('001004002');\">${Rows[0].Pay_Count}</a>  </span>条尚未处理的货款申请</li>" +
                            "{/if}" +
                            "{if Rows[0].PayBilling_Count!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithMenu('001002003');\">${Rows[0].PayBilling_Count} </a></span>条尚未审核的出库确认单等待审核</li>" +
                            "{/if}" +
                           "</ul>";

//待办事宜 模板
var rightTemplateByZsk = "<ul>" +
                            "{if Rows[0].PayBilling_Count!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithMenu('001002001');\">${Rows[0].PayBilling_Count}</a></span>条出库通知单尚未全部出库</li>" +
                            "{/if}" +
                            "{if Rows[0].RequetingCount!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithMenu('001004001');\">${Rows[0].RequetingCount} </a></span>条出库通知单已经出库确认，尚未申请资金</li>" +
                            "{/if}" +
                           "</ul>";

//待办事宜 模板
var rightTemplateByZskKz = "<ul>" +
                                "{if Rows[0].Pay_Count!=0}" +
                                    "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithMenu('001004003');\">${Rows[0].Pay_Count}</a> </span>条尚未处理的货款申请</li>" +
                                "{/if}" +
                           "</ul>";

// 业务提示 模板
var rightTemplateByZjzx2 = "<ul>" +
                             "{if Rows[0].Contract_Closing!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxContracting','即将到期的合同列表','Remind/Contracting.aspx?type=0');\">${Rows[0].Contract_Closing}</a> </span>条合同即将到期，尚未交割完成</li>" +
                             "{/if}" +
                             "{if Rows[0].Contract_Closed!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxContracted','已经到期的合同列表','Remind/Contracting.aspx?type=1');\">${Rows[0].Contract_Closed}</a> </span>条合同已经到期，尚未交割完成</li>" +
                             "{/if}" +
                             "{if Rows[0].Contract_Market_Confrim!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('ZjzxMarket_Confirm','品种详情列表','Remind/ContractConfirmStatusList.aspx?status=100');\">${Rows[0].Contract_Market_Confrim}</a> </span>条合同直属库粮食出库完成，交易市场尚未确认</li>" +
                             "{/if}" +
                             "{if Rows[0].Contract_MarketandOrg_Confrim!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('FgsMarket_Confirm','品种详情列表','Remind/ContractConfirmStatusList.aspx?status=200');\">${Rows[0].Contract_MarketandOrg_Confrim}</a> </span>条合同直属库粮食实际出库数量与交易市场确认数量不一致</li>" +
                             "{/if}" +
                           "</ul>";

//业务提示 模板
var rightTemplateByFgs2 = "<ul>" +
                            "{if Rows[0].RequetingCount!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('RequetingCount','出库数量尚未申请资金的合同','Remind/RequestMoneying.aspx');\">${Rows[0].RequetingCount}</a></span>条尚未申请资金的出库确认</li>" +
                            "{/if}" +
                            "{if Rows[0].Contract_Closing!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxContracting','即将到期的合同列表','Remind/Contracting.aspx?type=0');\">${Rows[0].Contract_Closing}</a></span>条合同即将到期，尚未交割完成</li>" +
                            "{/if}" +
                            "{if Rows[0].Contract_Closed!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxContracted','已经到期的合同列表','Remind/Contracting.aspx?type=1');\">${Rows[0].Contract_Closed}</a> </span>条合同已经到期，尚未交割完成</li>" +
                            "{/if}" +
                            "{if Rows[0].Contract_Market_Confrim!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('FgsMarket_Confirm','品种详情列表','Remind/ContractConfirmStatusList.aspx?status=100');\">${Rows[0].Contract_Market_Confrim} </a></span>条合同直属库粮食出库完成，交易市场尚未确认</li>" +
                            "{/if}" +
                            "{if Rows[0].Contract_MarketandOrg_Confrim!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('FgsMarket_Confirm','品种详情列表','Remind/ContractConfirmStatusList.aspx?status=200');\">${Rows[0].Contract_MarketandOrg_Confrim}</a></span>条合同直属库粮食实际出库数量与交易市场确认数量不一致</li>" +
                            "{/if}" +
                           "</ul>";

//业务提示 模板
var rightTemplateByZsk2 = "<ul>" +
                            "{if Rows[0].Contract_Closing!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxContracting','即将到期的合同列表','Remind/Contracting.aspx?type=0');\">${Rows[0].Contract_Closing}</a></span>条合同即将到期，尚未交割完成</li>" +
                            "{/if}" +
                            "{if Rows[0].Contract_Closed!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxContracted','已经到期的合同列表','Remind/Contracting.aspx?type=1');\">${Rows[0].Contract_Closed}</a></span>条合同已经到期，尚未交割完成</li>" +
                            "{/if}" +
                            "{if Rows[0].OverRuleNum!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxOverRule','已退回资金申请列表','Remind/OverRuleRequestMoneyDetailed.aspx');\">${Rows[0].OverRuleNum}</a></span>条货款申请已经被退回</li>" +
                            "{/if}" +
                            "{if Rows[0].CountPayMone!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxContracted','未查看的资金预拨详情','Remind/AllocateMoney.aspx');\">${Rows[0].CountPayMone}</a> </span>条尚未查看的预拨资金</li>" +
                            "{/if}" +
                            "{if Rows[0].Contract_Market_Confrim!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('ZjzxMarket_Confirm','品种详情列表','Remind/ContractConfirmStatusList.aspx?status=100');\">${Rows[0].Contract_Market_Confrim}</a></span>条合同直属库粮食出库完成，交易市场尚未确认</li>" +
                            "{/if}" +
                            "{if Rows[0].Contract_MarketandOrg_Confrim!=0}" +
                                "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('FgsMarket_Confirm','品种详情列表','Remind/ContractConfirmStatusList.aspx?status=200');\">${Rows[0].Contract_MarketandOrg_Confrim} </a></span>条合同直属库粮食实际出库数量与交易市场确认数量不一致</li>" +
                            "{/if}" +
                           "</ul>";

//业务提示 模板
var rightTemplateByZskKz2 = "<ul>" +
                                "{if Rows[0].Contract_Closing!=0}" +
                                    "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxContracting','即将到期的合同列表','Remind/Contracting.aspx?type=0');\">${Rows[0].Contract_Closing} </a></span>条合同即将到期，尚未交割完成</li>" +
                                "{/if}" +
                                "{if Rows[0].Contract_Closed!=0}" +
                                    "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxContracted','已经到期的合同列表','Remind/Contracting.aspx?type=1');\">${Rows[0].Contract_Closed}</a> </span>条合同已经到期，尚未交割完成</li>" +
                                "{/if}" +
                                "{if Rows[0].Contract_Market_Confrim!=0}" +
                                    "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('ZjzxMarket_Confirm','品种详情列表','Remind/ContractConfirmStatusList.aspx?status=100');\">${Rows[0].Contract_Market_Confrim}</a> </span>条合同直属库粮食出库完成，交易市场尚未确认</li>" +
                                "{/if}" +
                                "{if Rows[0].Contract_MarketandOrg_Confrim!=0}" +
                                    "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('FgsMarket_Confirm','品种详情列表','Remind/ContractConfirmStatusList.aspx?status=200');\">${Rows[0].Contract_MarketandOrg_Confrim}</a> </span>条合同直属库粮食实际出库数量与交易市场确认数量不一致</li>" +
                                "{/if}" +
                           "</ul>";

function loadRight(orgCode, m, templateStr, templateStr2) {
    $("#jstab1").html('<img src="res/images/framework/loading.gif" />');
    $("#jstab2").html('<img src="res/images/framework/loading.gif" />');
    function OnSuccess(result) {
        if (result.Rows != null) {
            $("#jstab1").html('<img src="res/images/framework/loading.gif" />');

            html = TrimPath.parseTemplate(templateStr).process(result);
            if (html == '<ul></ul>') {
                $("#jstab1").html('<div class="nodata">暂无数据</div>');
            } else {
                $("#jstab1").html(html);
            }
            html = TrimPath.parseTemplate(templateStr2).process(result);
            if (html == '<ul></ul>') {
                $("#jstab2").html('<div class="nodata">暂无数据</div>');
            } else {
                $("#jstab2").html(html);
            }
        }
    }
    $.ajax({ type: "POST", url: "Data/MainPageCustom.ashx", data: "m=" + m + "&orgcode=" + orgCode, dataType: "json", success: OnSuccess });

}



function loadqsData() {
    $("#qstab1").html('<img src="res/images/framework/loading.gif" />');
    $("#qstab2").html('<img src="res/images/framework/loading.gif" />');
    //alert('');
    function OnSuccess(result) {
        if (result != null) {
            $("#qstab1").html('<img src="res/images/framework/loading.gif" />');

            html = TrimPath.parseTemplate(qsTemplate).process(result);
            if (html == '<ul></ul>') {
                $("#qstab1").html('<div class="nodata">暂无数据</div>');
            } else {
                $("#qstab1").html(html);
            }
            html = TrimPath.parseTemplate(qsTemplate).process(result);
            if (html == '<ul></ul>') {
                $("#qstab2").html('<div class="nodata">暂无数据</div>');
            } else {
                $("#qstab2").html(html);
            }
        }
        else {
            $("#qstab1").html('<div class="nodata">暂无数据</div>');
            $("#qstab2").html('<div class="nodata">暂无数据</div>');
        }
    }
    function OnError() {
        alert('');
        $("#qstab1").html('<div class="nodata">暂无数据</div>');
        $("#qstab2").html('<div class="nodata">暂无数据</div>');
    }
    var loginCode = $('#hfdLoginCode').val();

    //定义模板
    var qsTemplate = "<ul>" +
                    "{for p in datas}" +
                    "{if p.count!=0}" +
                        "<li>有<span class=\"detail\"><a harf=\"javascript:void(0);\" " +
                        "onclick=\"openPanelWithOutMenu('zjzxqj','清算文件-清算进度'," +
                        "'http://125.46.15.206:8019/salt/loginServlet?url=SaltFileWeeklyLogEndPoint.html&userId=" + loginCode + "&fileId=${p.fileId}'" +
                        ");\">${p.count}</a></span> ${p.descrition}</li>" +
                    "{/if}" +
                    "{/for}" +
                  "</ul>";
    $.ajax({ type: "GET", url: "http://125.46.15.206:8019/salt/services/serviceforsafc/friendlyReminder/getFriendlayReminder?userId=" + loginCode + "&_type=json", dataType: "jsonp", success: OnSuccess, error: OnError });
}
function initRight() {
    var orgCode = $('#hfdOrgCode').val();
    var roleSign = $('#hfdRoleSign').val();
    var orgType = $('#hfdOrgType').val();
    var userMemo = $('#hfdUserMemo').val();
    if (roleSign == 'zjzx') {
        loadRight(orgCode, 'GetRemindZjzx', rightTemplateByZjzx, rightTemplateByZjzx2);
    }
    else if (roleSign == 'fgs') {
        loadRight(orgCode, 'GetRemindFgs', rightTemplateByFgs, rightTemplateByFgs2);
    }
    else if (roleSign == 'zskkz') {
        loadRight(orgCode, 'GetRemindZsk', rightTemplateByZskKz, rightTemplateByZskKz2);
    }
    else if (roleSign == 'zsk') {
        loadRight(orgCode, 'GetRemindZsk', rightTemplateByZsk, rightTemplateByZsk2);
    }
    else if (orgCode == 'SA0100010000001') {
        loadRight(orgCode, 'GetRemindZjzx', rightTemplateByZjzx, rightTemplateByZjzx2);
        //document.getElementsByName('detail');
        //$("span[name='detail']").css("display", 'none');
    }
    else if (orgType == 'FGS') {
        loadRight(orgCode, 'GetRemindFgs', rightTemplateByFgs, rightTemplateByFgs2);
        //document.getElementsByName('detail');
        //$("span[name='detail']").css("display", 'none');
    }
    else if (orgType == 'ZSK') {
        loadRight(orgCode, 'GetRemindZsk', rightTemplateByZsk, rightTemplateByZsk2);
        //document.getElementsByName('detail');
        //$("span[name='detail']").css("display", 'none');
    }
    else {
        loadRight(orgCode, 'GetRemindZjzx', rightTemplateByZjzx, rightTemplateByZjzx2);
        //document.getElementsByName('detail');
        //$("span[name='detail']").css("display", 'none');
    }
    if (userMemo == 'CX') {
        //$("span[name='detail']").css("display", 'none');
    }

    loadqsData();
}

$(document).ready(function() {
    loadMenu();
    initRight();
});

function loadMenu() {
    loadCustomMenu($('#hfdUserCode').val(), $('#hfdParnetMenu').val(), $('#hfdMenuType').val(), $('#hfdMenuGroup').val());
}